//package com.zmn.plat.task.job.categgroup;
//
//import com.github.ltsopensource.core.domain.Action;
//import com.github.ltsopensource.core.domain.Job;
//import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
//import com.github.ltsopensource.spring.tasktracker.LTS;
//import com.github.ltsopensource.tasktracker.Result;
//import com.zmn.common.constant.StatusConsts;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.collection.CollectionUtil;
//import com.zmn.common.utils.date.DateUtil;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.manager.lts.interfaces.task.TaskManager;
//import com.zmn.plat.manager.utils.TaskConsts;
//import com.zmn.plat.model.entity.servcategory.ServAssCategory;
//import com.zmn.plat.model.vo.servcategory.ServAssCategoryVO;
//import com.zmn.plat.services.interfaces.servcategory.ServAssCategoryService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//
///**
// * 描述:描述: 执行后台产品分类生效产品组任务提交
// *
// * @auther tanghongjun
// * @since 2020/9/11
// */
//@LTS
//public class CategProductGroupJob {
//
//    private Logger logger = LoggerFactory.getLogger(CategProductGroupJob.class);
//
//    @Resource
//    TaskManager taskManager;
//    @Resource
//    ServAssCategoryService servAssCategoryService;
//
//    /**
//     * 描述:描述: 执行后台产品分类生效产品组任务提交
//     *
//     * @auther tanghongjun
//     * @since 2020/9/11
//     */
//    @PostConstruct
//    void init() {
//        Job job = new Job();
//        job.setTaskId(TaskConsts.TASK_ID_CATEG_PRODUCT_GROUP);
//        job.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_CATEG_PRODUCT_GROUP);
//        job.setCronExpression("0 0/0 0 * * ?");
//        job.setReplaceOnExist(true);
//        ResponseDTO<String> result = taskManager.submitTask2(job);
//        if (!result.isSuccess() || !Objects.equals(result.getStatus(), StatusConsts.STATUS_SUCCESS)) {
//            logger.error("#CategProductGroup# job submit fail...");
//        }
//    }
//
//    /**
//     * 执行后台产品分类生效产品组
//     *
//     * @param job the job
//     * @return result
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_CATEG_PRODUCT_GROUP)
//    public Result runCategProductGropJob(Job job) {
//
//        logger.debug("#job#CategProductGroup#start running...");
//
//        // 查询今天需要生效的产品组
//        List<ServAssCategoryVO> servAssCategoryVOList = servAssCategoryService.listByPerTime(DateUtil.getDateStart(DateUtil.getNow()));
//
//        if (CollectionUtil.isNullOrEmpty(servAssCategoryVOList)) {
//            return new Result(Action.EXECUTE_SUCCESS, "当天没有需要生效的分组");
//        }
//
//        ServAssCategory servAssCategory;
//        ServAssCategoryVO servAssCategoryVO;
//        List<ServAssCategory> servAssCategoryList = new ArrayList<>(servAssCategoryVOList.size());
//
//        for (int i = 0; i < servAssCategoryVOList.size(); i++) {
//            servAssCategoryVO = servAssCategoryVOList.get(i);
//            servAssCategory = new ServAssCategoryVO();
//
//            if (NumberUtil.isNullOrZero(servAssCategoryVO.getGroupId())) {
//                continue;
//            }
//
//            servAssCategory.setGroupId(servAssCategoryVO.getGroupId());
//            servAssCategory.setProductGroupcId(NumberUtil.isPositiveInteger(servAssCategoryVO.getPerProductGroupcId()) ? servAssCategoryVO.getPerProductGroupcId() : servAssCategoryVO.getProductGroupcId());
//            servAssCategory.setProductGroupcName(NumberUtil.isPositiveInteger(servAssCategoryVO.getPerProductGroupcId()) ? servAssCategoryVO.getPerProductGroupcName() : servAssCategoryVO.getProductGroupcName());
//            servAssCategory.setProductGroupfId(NumberUtil.isPositiveInteger(servAssCategoryVO.getPerProductGroupfId()) ? servAssCategoryVO.getPerProductGroupfId() : servAssCategoryVO.getProductGroupfId());
//            servAssCategory.setProductGroupfName(NumberUtil.isPositiveInteger(servAssCategoryVO.getPerProductGroupfId()) ? servAssCategoryVO.getPerProductGroupfName() : servAssCategoryVO.getProductGroupfName());
//            servAssCategory.setProductGroupbId(NumberUtil.isPositiveInteger(servAssCategoryVO.getPerProductGroupbId()) ? servAssCategoryVO.getPerProductGroupbId() : servAssCategoryVO.getProductGroupbId());
//            servAssCategory.setProductGroupbName(NumberUtil.isPositiveInteger(servAssCategoryVO.getPerProductGroupbId()) ? servAssCategoryVO.getPerProductGroupbName() : servAssCategoryVO.getProductGroupbName());
//
//            servAssCategoryList.add(servAssCategory);
//        }
//
//        if (CollectionUtil.isNullOrEmpty(servAssCategoryList)) {
//            return new Result(Action.EXECUTE_SUCCESS, "当天没有需要生效的分组");
//        }
//        Integer count = servAssCategoryService.updateProductGroupByKeyBatch(servAssCategoryList);
//
//        logger.debug("#job#CategProductGroup#end running... update count :" + count);
//        return new Result(Action.EXECUTE_SUCCESS, "分类管理生效产品组完成! update count:" + count);
//    }
//
//}
